Skip to content

Support microagent repo.md with new MCP tool format - #154

Merged
xingyaoww merged 1 commit into
mainfrom
openhands/support-mcp-tools-in-microagents
Sep 8, 2025
Merged

xingyaoww merged 1 commit into
mainfrom
openhands/support-mcp-tools-in-microagents

Conversation

@xingyaoww

Copy link
Copy Markdown
Contributor

Summary

This PR implements support for loading mcp_tools from microagent frontmatter, as requested in issue #153.

Changes

  • Updated BaseMicroagent.load(): Modified to extract mcp_tools from frontmatter metadata and pass it to the RepoMicroagent constructor
  • Enhanced type safety: Added proper type casting to satisfy the strict type checker
  • Comprehensive test coverage: Added 4 new test functions covering:
    • YAML format mcp_tools configuration
    • JSON format mcp_tools configuration
    • Microagents without mcp_tools (None case)
    • Invalid mcp_tools configuration (error handling)

Supported Formats

The implementation supports both YAML and JSON formats in the frontmatter:

YAML format:

---
name: default-tools
type: repo
version: 1.0.0
agent: CodeActAgent
mcp_tools:
  mcpServers:
    fetch:
      command: uvx
      args: ["mcp-server-fetch"]
---

JSON format:

---
name: default-tools
type: repo
version: 1.0.0
agent: CodeActAgent
mcp_tools: {
  "mcpServers": {
    "fetch": {
      "command": "uvx",
      "args": ["mcp-server-fetch"]
    }
  }
}
---

Testing

  • All existing tests continue to pass
  • New tests verify correct loading and validation of mcp_tools
  • Pre-commit hooks pass (formatting, linting, type checking)
  • Error handling tested for invalid configurations

Fixes

Closes #153

@xingyaoww can click here to continue refining the PR

- Updated BaseMicroagent.load() to extract mcp_tools from frontmatter
- Modified RepoMicroagent constructor to accept mcp_tools parameter
- Added comprehensive test coverage for mcp_tools functionality
- Supports both YAML and JSON formats in frontmatter
- Includes error handling for invalid configurations

Fixes #153

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report
FileStmtsMissCoverMissing
openhands
   __init__.py10100% 
openhands/sdk
   __init__.py14285%22–23
   logger.py732171%33, 57, 64–67, 69–71, 124, 130–132, 135–136, 142–144, 151, 156–157
openhands/sdk/agent
   __init__.py30100% 
   base.py46491%36, 47, 83, 103
openhands/sdk/agent/agent
   __init__.py20100% 
   agent.py1282878%73–75, 132–133, 135–137, 139–141, 175, 189, 210, 240, 272–277, 284–285, 289–291, 319, 326
openhands/sdk/context
   __init__.py40100% 
   agent_context.py57296%146, 152
   manager.py330%1, 4–5
   view.py47687%46–50, 52
openhands/sdk/context/condenser
   __init__.py30100% 
   condenser.py17382%68–69, 73
   no_op_condenser.py60100% 
openhands/sdk/context/microagents
   __init__.py40100% 
   exceptions.py50100% 
   microagent.py1432582%129, 132–135, 217–220, 228, 250–251, 256–257, 259, 263, 270–272, 280–282, 336, 338–339
   types.py300100% 
openhands/sdk/context/utils
   __init__.py20100% 
   prompt.py30583%12, 15, 24, 44–45
openhands/sdk/conversation
   __init__.py50100% 
   conversation.py83890%70, 78, 86–88, 92–93, 149
   state.py28292%47–48
   types.py30100% 
   visualizer.py1442483%46, 71, 84, 110, 112, 114, 117, 166–168, 171–172, 174, 197, 227, 231, 238, 241, 244–245, 268–270, 272
openhands/sdk/event
   __init__.py50100% 
   base.py672070%38, 42, 62, 66–68, 70–75, 77–78, 80–82, 84–85, 87
   condenser.py25580%29, 33–35, 49
   llm_convertible.py991485%28–29, 34–35, 168–169, 174, 182, 213–214, 219, 240–241, 246
   types.py30100% 
   user_action.py6183%12
   utils.py110100% 
openhands/sdk/llm
   __init__.py60100% 
   exceptions.py360100% 
   llm.py41413866%269, 274, 287–289, 293–294, 326, 365, 369, 379, 385–386, 403–404, 474, 487–488, 493–494, 496–497, 499–502, 507–509, 513–515, 532–533, 536–538, 541–542, 550–551, 556, 559, 561–562, 566–567, 570–574, 584–587, 592–597, 601–602, 611–613, 616–617, 641, 647–648, 694, 743, 749, 752, 761–762, 771, 778, 781, 785–787, 791, 793–798, 800–817, 820–824, 826–827, 833–842, 846–857
   llm_registry.py380100% 
   message.py100298%201–202
   metadata.py150100% 
openhands/sdk/llm/utils
   fn_call_converter.py34311267%74, 343, 345, 348–349, 367, 369, 375, 381, 383, 422, 424, 426, 428, 433–434, 481–482, 518–520, 522, 524, 545–547, 553, 575, 601–602, 610–613, 615, 617, 639, 648, 656, 701–704, 708–711, 723, 727, 738, 748, 794, 796–798, 800, 803, 819–821, 823–826, 829, 833, 844–845, 859, 866–867, 870–871, 875–876, 882–883, 886, 905–908, 912–913, 918–919, 924, 973–974, 980, 994, 1006, 1008–1009, 1012–1014, 1016–1017, 1023–1025, 1027–1028, 1030, 1032, 1036, 1038, 1043, 1045–1046, 1049
   metrics.py110298%17, 113
   model_features.py400100% 
   telemetry.py116992%71, 94, 99–100, 112–113, 120, 192, 208
openhands/sdk/mcp
   __init__.py50100% 
   client.py631182%41, 56–57, 78, 82, 94–95, 105–106, 112–113
   definition.py27196%54
   tool.py381365%33–36, 40, 43, 46–49, 89–90, 95
   utils.py30486%23–24, 27, 30
openhands/sdk/tool
   __init__.py40100% 
   schema.py94693%23–25, 27, 36, 204
   security_prompt.py30100% 
   tool.py821186%51, 107, 129, 149, 152–158
openhands/sdk/tool/builtins
   __init__.py30100% 
   finish.py150100% 
openhands/sdk/utils
   __init__.py20100% 
   discriminated_union.py56591%156, 195, 200, 207, 210
   json.py28280%1–3, 5, 7–8, 11, 14–21, 25, 28, 30–31, 34, 37–38, 40, 43, 45–48
   truncate.py100100% 
openhands/tools
   __init__.py8275%37–38
openhands/tools/execute_bash
   __init__.py40100% 
   constants.py90100% 
   definition.py411465%65, 69–78, 148, 151, 159
   impl.py10190%38
   metadata.py502354%67–73, 77–78, 83, 85, 87–96, 100–101
openhands/tools/execute_bash/terminal
   __init__.py60100% 
   factory.py492842%24–25, 30, 32, 35, 37–38, 44–46, 74–77, 79–83, 87–89, 91, 97, 107, 111–113
   interface.py661675%43, 52, 62, 71, 76, 85, 94, 99, 104, 112, 145, 157, 162, 171, 180, 185
   subprocess_terminal.py23620313%33–34, 50–53, 56, 59–61, 67–68, 70–73, 75, 78, 80–82, 96–99, 101, 104–105, 108, 111–112, 116–117, 123–125, 127, 130–131, 133, 137–138, 140–141, 143–149, 151–157, 160–165, 167–168, 170–171, 176, 178–186, 190–192, 194–195, 197–198, 201–203, 205–208, 210–211, 213–214, 216–221, 226–228, 230, 233, 236–237, 240–241, 247–249, 251–258, 260–263, 267–275, 288–289, 291, 308–309, 312–313, 315, 317, 319–321, 324–325, 327–329, 331–332, 334–335, 344–345, 349, 351–356, 360–361, 363–366, 368–374, 376–377, 379–383, 387–388, 390–396, 400–401, 404–405, 407–408, 410–412
   terminal_session.py17813623%43, 86, 92, 96–98, 107–108, 119–121, 123–126, 135–136, 140, 144, 147–148, 150, 155, 161, 163–164, 169, 177, 182–185, 198–200, 205, 208–209, 213, 219, 233–235, 240, 243–244, 248, 255, 264, 273–274, 276, 279–283, 285, 288, 290–292, 296–297, 300–302, 306, 311–312, 316–317, 323–325, 336–337, 340–342, 344–346, 349, 359, 363, 366, 369–370, 376–377, 383, 388–389, 392–396, 402, 404–406, 412–416, 419, 422, 425–426, 428–431, 438, 442, 447–448, 455–457, 461, 465, 470–471, 475–476, 479–482, 488–489, 492
   tmux_terminal.py752764%35, 41, 85, 97–98, 100, 108–109, 111, 118, 123, 135–142, 150–151, 153–154, 156, 158–160
openhands/tools/execute_bash/utils
   command.py817211%15–19, 27, 32, 34–35, 37–38, 41–46, 48, 51–53, 55, 58–67, 74–75, 77–79, 81, 83, 90–91, 93, 95–97, 99, 101–102, 105–106, 109, 117, 120–121, 123–124, 127–129, 132–138, 141–145, 150
openhands/tools/str_replace_editor
   __init__.py30100% 
   definition.py33487%78, 145, 148, 151
   editor.py22817025%74, 76–77, 80, 99, 102, 111–115, 121–129, 131, 149–150, 170–171, 175, 179–180, 189, 193–196, 204–205, 209–211, 217, 220, 225, 228, 231–232, 235, 238–239, 243, 247, 261–263, 272, 275, 281, 286, 288–292, 294, 296, 300–301, 305–306, 314–315, 317–320, 322, 328–329, 335–337, 345–349, 353, 355–356, 363, 366, 371–372, 374, 397–398, 420–421, 423–424, 430, 433, 437–443, 446–447, 450–455, 458, 461–462, 466, 469–470, 473, 475–476, 482, 486, 504, 509–512, 514, 522, 529, 536, 547–550, 552, 554, 580–583, 592–593, 622–624, 626–635, 640–643, 656–657, 662, 667, 673, 679
   exceptions.py221340%5–6, 9, 16–18, 25–27, 38–41
   impl.py261157%31–32, 49–50, 52–54, 63–66
openhands/tools/str_replace_editor/utils
   __init__.py00100% 
   config.py20100% 
   constants.py50100% 
   encoding.py542750%42–43, 46–48, 51, 54, 60, 64–65, 67, 69, 78, 80–81, 84, 87–90, 93, 96–97, 114, 128, 130–131
   file_cache.py954849%43–46, 49–50, 54, 59, 61, 64, 69, 72–73, 87, 95–98, 108–112, 115–120, 126–130, 133–135, 138–140, 143–148, 151, 154
   history.py663645%58–60, 66–68, 70–71, 74–76, 78–79, 82, 85–86, 88, 92–94, 98–99, 102–104, 107, 111–113, 115–120, 122
   shell.py231630%30, 32–34, 38, 40, 51–55, 62–63, 70–72
openhands/tools/utils
   __init__.py00100% 
TOTAL4145136267% 

@xingyaoww
xingyaoww merged commit fdc0aaf into main Sep 8, 2025
@xingyaoww
xingyaoww deleted the openhands/support-mcp-tools-in-microagents branch September 8, 2025 17:47
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
Co-authored-by: openhands <openhands@all-hands.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support microagent repo.md with new MCP tool format

2 participants